#include "core/gamestream/GameStreamManager.h"
#include "core/gamestream/XComponentBackend.h"
#include "core/utils/NapiUtils.h"
#include "napi/native_api.h"


#undef LOG_DOMAIN
#undef LOG_TAG
#define LOG_DOMAIN  0x0
#define LOG_TAG     "LibGamestreamXComponentNapiInit"
#include <hilog/log.h>

EXTERN_C_START
static napi_value Init(napi_env env, napi_value exports) {
    if (auto ret = GameStreamManager::exportNapi(env, exports); ret != napi_ok) {
        napi_throw_error(env, "RuntimeError", "Failed to inject GameStreamManager apis");
        return nullptr;
    }
    if (auto ret = XComponentBackend::registerCallbacks(env, exports, GameStreamManager::xcomponentId); ret != napi_ok) {
        napi_throw_error(env, "RuntimeError", "Failed to inject XComponent callbacks");
        return nullptr;
    }
    OH_LOG_DEBUG(LOG_APP, "Successfully injected all NAPIs");
    return exports;
}
EXTERN_C_END

static napi_module demoModule = {
    .nm_version = 1,
    .nm_flags = 0,
    .nm_filename = nullptr,
    .nm_register_func = Init,
    .nm_modname = "gamestream_xcomponent",
    .nm_priv = ((void*)0),
    .reserved = { 0 },
};

extern "C" __attribute__((constructor)) void RegisterGameStreamXComponentModule(void)
{
    napi_module_register(&demoModule);
}
